package com.enfo.zjabank.tool;

import java.io.File;

/**
 * Created by zhoum on 2016/8/2.
 */
public class FileUtil {
    public static String getFileType(String suffix){
        if(StringUtil.isEmpty(suffix)){
            return "";
        }
        if(suffix.endsWith("png") || suffix.endsWith("jpg") || suffix.endsWith("gif")){
            return "image";
        }
        if(suffix.endsWith("zip") || suffix.endsWith("rar") || suffix.endsWith("7z")){
            return "archive";
        }
        if(suffix.endsWith("docx") || suffix.endsWith("docx") || suffix.endsWith("pdf") || suffix.endsWith("xls") || suffix.endsWith("xlsx") || suffix.endsWith("txt")){
            return "office";
        }
        if(suffix.endsWith("txt") || suffix.endsWith("log")){
            return "text";
        }
        return "";
    }
    public static void deleteFiles(String path){
        File file = new File(path);
        if(file.isDirectory()){
            String[] children = file.list();
            for (String child:children){
                String fullPath = path+File.separator+child;
                deleteFiles(fullPath);
                file.delete();
            }
        }else{
            file.delete();
        }
    }
}
